<template>
  <div>
    <el-container>
      <el-header style="margin-bottom: 20px">
        <!--            <h1>物资操作流水记录</h1>-->
        <label style="color: darkturquoise;font-weight: bolder;font-size: xxx-large">我的订单</label>
      </el-header>
    </el-container>
    <!--      <el-button @click="resetDateFilter">清除日期过滤器</el-button>-->
    <!--      <el-button @click="clearFilter">清除所有过滤器</el-button>-->
    <el-card>
      <el-table border ref="filterTable" :data="tableData" style="width: 100%">
        <el-table-column prop="buyTime" label="购买日期" sortable width="180" column-key="date">
        </el-table-column>
        <el-table-column prop="userName" label="购买人" width="180"></el-table-column>
        <el-table-column prop="sightName" label="景点名称" width="180"></el-table-column>
        <el-table-column prop="ticketName" label="票类型" width="180"></el-table-column>
        <el-table-column prop="price" label="价格" width="100"></el-table-column>
        <el-table-column label="是否使用" width="120" prop="sex">
          <template slot-scope="scope">
            {{ scope.row.used === 0 ? '未使用' : '' }}
            {{ scope.row.used === 1 ? '已使用' : '' }}
          </template>
        </el-table-column>
        <el-table-column prop="useTime" label="使用时间"></el-table-column>

        <el-table-column prop="status" label="操作" width=""
                         :filters="[{ text: '未使用', value: 0 }, { text: '已使用', value: 1 }]" :filter-method="filterTag"
                         filter-placement="bottom-end">
          <template slot-scope="scope">
            <!--            <el-button style="margin-right: 10px" type="primary" size="mini"-->
            <!--                       @click="deleteOrder(scope.row)">取消订单</el-button>-->
            <el-popconfirm @confirm="deleteOrder(scope.row)" title="确定要取消订单么？">
              <el-button v-if="scope.row.cancel===0&&scope.row.used===0" style="margin-left:10px" slot="reference" class="deleteBtn" type="danger"
                         size="mini">取消订单</el-button>
            </el-popconfirm>
            <el-button v-if="scope.row.cancel===1" style="margin-left:10px" slot="reference" class="deleteBtn" type="primary"
                       size="mini">已取消订单</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-row>
      <el-col :span="12" :offset="12">
        <el-pagination layout="total,prev, pager, next,jumper,sizes " background small prev-text="上一页" next-text="下一页"
                       :total="total" :page-size="pageSize" :current-page="pageNow" :page-sizes="[10, 20, 50]" style="margin:15px 0px"
                       @current-change="findPage" @size-change="findSize">
        </el-pagination>
      </el-col>
    </el-row>
    <!--    &lt;!&ndash;      个人信息展示&ndash;&gt;-->
    <el-dialog title="我的评论" :visible.sync="commentsShow" :append-to-body="true" :modal-append-to-body="false">
      <el-form :model="form">
        <el-form-item label="品论内容" width="50%" :label-width="formLabelWidth">
          <el-input v-model="form.content" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="commentsShow = false">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: 'orderManagement',
  data() {
    return {
      form: {
        content: '',

      },
      formLabelWidth: '120px',
      commentsShow: false,
      pageNow: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
      orderDetailShow: false,
      size: '',
      orderDetail: {
        user: 'medium'
      }
    };
  },

  mounted() {
    this.getMyOrder()
    // this.$bus.$on("getMyOrder",this.refreshMsg)
  },
  beforeDestroy() {
    // this.$bus.$off("getMyOrder")
  },

  methods: {

    toComments() {
      this.commentsShow = true;
    },

    //添加类型表单
    submitForm() {
      this.commentsShow = false
      console.log(this.form)
      this.$http.post("/dept/addDept", this.form).then(res => {
        console.log(res.data)
        if (res.data.status) {
          this.$message({
            message: res.data.data,
            type: 'success'
          });
        } else {
          this.$message.error(res.data.msg);
        }
      })
      this.form = {}
      this.findPage(this.pageNow)
    },

    deleteOrder(item) {
      console.info(item)
      this.$http.put("/order/cancel/" + item.id).then(res => {
        console.log(res.data)
        // console.log(this.userDetail)
        this.$message({
          message: res.data.data,
          type: 'success'
        });
        this.findPage(this.pageNow)
      });

    },

    refreshMsg() {
      console.log("子页面接收到消息了")
      this.getMyOrder()
    },
    //改变页码数据量大小
    findSize(size) {
      this.pageSize = size
      this.getMyOrder()
    },
    changeMsgStatus(mid) {
      this.$http.put("/order/status/" + mid).then(res => {
        // console.log(res.data)
      });
      this.getMyOrder()
    },
    findPage(page) {
      this.pageNow = page
      this.getMyOrder()

    },
    //获取消息列表
    getMyOrder() {
      let uid = JSON.parse(window.sessionStorage.getItem("user")).id
      this.$http.get("/order/my/" + this.pageNow + "/" + this.pageSize + "/" + uid).then(res => {
        console.log(res.data.data)
        this.tableData = res.data.data.records
        this.total = res.data.data.total
      })
    },


    formatter(row, column) {
      return row.content;
    },
    filterTag(value, row) {
      return row.status === value;
    },
    filterHandler(value, row, column) {
      const property = column['property'];
      return row[property] === value;
    }
  },

};
</script>

<style lang="less" scoped></style>
